package Code.Day2_20240919.com.dx.day02;

import java.util.Scanner;

/**
 * @ClassName Exam01
 * @Description 0919晨考
 * @Author 12994
 * @Date 2024/9/19 10:01
 * @Version 1.0
 **/
public class Exam01 {
    public static void main(String[] args) {
        // 操作数1 操作数2 结果 余数(如果有)
        double x, y, r, r1;
        char act;
        Scanner input = new Scanner(System.in);
        System.out.print("请输入第一个操作数: ");
        x = input.nextDouble();
        System.out.print("请输入第二个操作数: ");
        y = input.nextDouble();
        System.out.print("请输入计算符: ");
        act = input.next().charAt(0);

        // do
        switch (act) {
            case '+':
                // 整型直接提升
                r = x + y;
                System.out.println("计算结果为: " + r);
                break;
            case '-':
                r = x - y;
                System.out.println("计算结果为: " + r);
                break;
            case '*':
                r = x * y;
                System.out.println("计算结果为: " + r);
                break;
            case '/':
                if (y == 0D) {
                    System.out.println("除数不能为零!");
                    break;
                }
                r = x / y;
                r1 = x % y;
                // System.out.println("除法结果为: " + r + " ,余数为: " + r1);
                System.out.println("除法结果为: " + r);
                break;
            default:
                System.out.println("非法的操作符, 请重新输入!");
                main(args);
                break;
        }
    }
}
